package org.fujene.memman;

import org.fujene.memoryblock.dictionary.DictionaryPackage;
import org.fujene.structure.LookupPointer;

public class TermInformation{
	private DictionaryPackage term;
	private LookupPointer previous, next;
	private int skipPoint;
	private boolean isFound;
	private boolean appendSkipPointer;
	private SkipState skipState;

	public enum SkipState{
		behindFirst, first, middle, last, behindLast;
	}

	public TermInformation(DictionaryPackage pkg){
		this.term = pkg;
		this.isFound = (pkg != null);
		this.skipPoint = -1;
		this.skipState = SkipState.behindFirst;
	}

	public TermInformation skipptr(int index){
		this.skipPoint = index;
		return this;
	}

	public int getSkipIndex(){
		return skipPoint;
	}

	public void deleteInvIndex(int index){
		this.term.deleteInvIndex(index);
	}

	public TermInformation appendSkip(boolean isAppend){
		this.appendSkipPointer = isAppend;
		return this;
	}

	public TermInformation behindFirst(LookupPointer next){
		this.skipState = SkipState.behindFirst;
		this.next = next;
		return this;
	}

	public TermInformation first(LookupPointer next){
		this.skipState = SkipState.first;
		this.next = next;
		return this;
	}

	public TermInformation middle(LookupPointer previous, LookupPointer next){
		this.skipState = SkipState.middle;
		this.previous = previous;
		this.next = next;
		return this;
	}

	public TermInformation last(LookupPointer previous){
		this.skipState = SkipState.last;
		this.previous = previous;
		return this;
	}

	public TermInformation behindLast(LookupPointer previous){
		this.skipState = SkipState.behindLast;
		this.previous = previous;
		return this;
	}

	public TermInformation dictionary(DictionaryPackage pkg){
		this.term = pkg;
		return this;
	}

	public DictionaryPackage getDictionary(){
		return term;
	}

	public boolean isFound(){
		return isFound;
	}

	public boolean isBehindFirst(){
		return skipState == SkipState.behindFirst;
	}

	public boolean isFirst(){
		return skipState == SkipState.first;
	}

	public boolean isMiddle(){
		return skipState == SkipState.middle;
	}

	public boolean isLast(){
		return skipState == SkipState.last;
	}

	public boolean isBehindLast(){
		return skipState == SkipState.behindLast;
	}

	public LookupPointer getPrevious(){
		return previous;
	}

	public LookupPointer getNext(){
		return next;
	}

	public boolean isAppendSkipPointer(){
		return appendSkipPointer;
	}

	public boolean isInDict(){
		return(skipState != SkipState.behindFirst || skipState == SkipState.behindLast);
	}
}
